package cn.itcast.solr;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class IndexCreateCloud {

    @Test
    public void testCreateIndex() throws IOException, SolrServerException {
        CloudSolrServer solrServer = new CloudSolrServer("192.168.206.101:2181,192.168.206.102:2181,192.168.206.103:2181");

         solrServer.setDefaultCollection("myCollection1");


        SolrInputDocument document = new SolrInputDocument();
        document.addField("id","10066");
        document.addField("title","下雨永远不止");

        solrServer.add(document);

        solrServer.commit();
    }

    @Test
    public void testQueryIndex() throws IOException, SolrServerException {
        CloudSolrServer solrServer = new CloudSolrServer("192.168.206.101:2181,192.168.206.102:2181,192.168.206.103:2181");

        solrServer.setDefaultCollection("myCollection1");

        SolrQuery solrQuery = new SolrQuery("title:下雨");

        QueryResponse query = solrServer.query(solrQuery);

        solrServer.commit();
    }
}
